<video id="video" autoplay playsinline controls></video>
<script>
    (async () => {
        const video = document.getElementById("video");
        const res = await fetch("http://localhost:8889/whep/mystream", {
            method: "POST",
            headers: {"Accept": "application/sdp"},
        });
        const offer = await res.text();

        const pc = new RTCPeerConnection();
        pc.ontrack = (event) => {
            video.srcObject = event.streams[0];
        };

        await pc.setRemoteDescription({type: "offer", sdp: offer});
        const answer = await pc.createAnswer();
        await pc.setLocalDescription(answer);

        await fetch("http://localhost:8889/whep/mystream", {
            method: "PATCH",
            headers: {"Content-Type": "application/sdp"},
            body: pc.localDescription.sdp,
        });
    })();
</script>
